package org.niu.tree;


import java.util.ArrayList;
import java.util.List;

public class ThreeNode {
    List<Integer> list = new ArrayList<>();
    public int[][] threeOrders (TreeNode root) {
        // write code here
        preOrder(root);
        int n = list.size();
        int[][] ans = new int[3][n];
        for (int j = 0; j < n;j++){
                ans[0][j] = list.get(j);
        }
        list.clear();
        inOrder(root);
        for (int j = 0; j < n;j++){
            ans[1][j] = list.get(j);
        }
        list.clear();
        postOrder(root);
        for (int j = 0; j < n;j++){
            ans[2][j] = list.get(j);
        }
return ans;
    }
    void preOrder(TreeNode root){
        if(root==null){
            return;
        }
        list.add(root.val);
        preOrder(root.left);
        preOrder(root.right);
    }
    void inOrder(TreeNode root){
        if(root==null){
            return;
        }
        inOrder(root.left);
        list.add(root.val);
        inOrder(root.right);
    }
    void postOrder(TreeNode root){
        if(root==null){
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        list.add(root.val);
    }
}
